{include file='admin/header.html'}

<!-- 顶部 -->
<!-- 移动端样式 -->
<style>
  body{background-color:#f2f2f2}
  .layui-layout-admin .layui-logo{color:#fff;background-color:rgba(0,0,0,.3)}
  .layui-layout-admin .layui-body{overflow-y:hidden}
  .layui-layout-admin .layui-side-shrink{left:-300px}
  .layui-layout-admin .layui-logo-shrink{left:-300px}
  .layui-layout-admin .layui-body-shrink{left:0}
  .layui-layout-admin .layui-layout-left-shrink{left:0}
  .layui-layout-admin .layui-footer-shrink{left:0}

  /* 移动端 */
  @media screen and (max-width:768px){
    .layui-layout-admin .layui-body,.layui-layout-admin .layui-footer,.layui-layout-admin .layui-layout-left{left:0}
    .layui-layout-admin .layui-side{left:-300px;z-index:1000}
    .layui-layout-admin .layui-header{z-index:999}
    .layui-layout-admin .layui-logo{z-index:1000}
    .site-mobile .layui-side{left:0}
    /* 遮罩层 */
    .site-mobile .site-mobile-shade{position:fixed;top:0;bottom:0;left:0;right:0;background-color:rgba(0,0,0,.3);z-index:999}
  }
</style>
<!-- 移动端样式end -->
<div class="site-mobile-shade" lay-header-event="menuShrink"></div>

<div class="layui-layout layui-layout-admin">
  <!-- header start -->
  <div class="layui-header">
    <!-- logo -->
    <div class="layui-logo layui-hide-xs" style="background:#23262E;cursor:pointer;" lay-header-event="backend"><i class="layui-icon layui-icon-console"></i> 后台</div>
    <!-- 头部左侧区域 -->
    <ul class="layui-nav layui-layout-left">
      <!-- 移动端显示 -->
      <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" lay-header-event="menuLeft">
        <i class="layui-icon layui-icon-spread-left"></i>
      </li>
      <li class="layui-nav-item layui-show-md-inline-block layui-hide-xs" lay-header-event="menuLeftShrink">
        <i class="layui-icon layui-shrink layui-icon-shrink-right"></i>
      </li>
      <li class="layui-nav-item">
        <a href="{$site_url}/" target="_blank" title="前台"><i class="layui-icon layui-icon-website"></i></a>
      </li>
      <li class="layui-nav-item layui-hide-xs">
        <a href="javascript:;" lay-header-event="refresh" title="刷新"><i class="layui-icon layui-icon-refresh-3"></i></a>
      </li>
    </ul>
    <!-- 头部左侧区域end -->
    <!-- 头部右侧区域 -->
    <ul class="layui-nav layui-layout-right">
      <li class="layui-nav-item layui-hide-xs" lay-unselect="">
        <a href="javascript:;" lay-header-event="fullscreen">
          <i class="layui-icon layui-icon-screen-full"></i>
        </a>
      </li>
      <li class="layui-nav-item">
        <a href="javascript:;"><img src="{$avatar}" class="layui-nav-img" alt="avatar">{$username}</a>
        <dl class="layui-nav-child">
          <dd><a href="javascript:;" title="修改资料" lay-header-event="profile">修改资料</a>
          </dd>
          <dd><a href="javascript:;" title="清除缓存" lay-header-event="clear">清除缓存</a>
          </dd>
          <dd><a href="javascript:;" title="登出" lay-header-event="logout">登出</a></dd>
        </dl>
      </li>
      <li class="layui-nav-item" lay-header-event="menuRight" lay-unselect>
        <a href="javascript:;">
          <i class="layui-icon layui-icon-more-vertical"></i>
        </a>
      </li>
    </ul>
    <!-- 头部右侧区域end -->
  </div>
  <!-- header end -->

  <!-- aside start -->
  <div class="layui-side layui-bg-black">
    <div class="layui-side-scroll">
      <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
      <ul class="layui-nav layui-nav-tree" lay-filter="test">
        <!-- 树型菜单 -->
        {$menus}
        <!-- 树型菜单end -->
      </ul>
      <!-- 左侧导航区end -->
    </div>
  </div>
  <!-- aside end -->

  <!-- main start -->
  <div class="layui-body" id="main-body">
    <!-- 内容主体区域 -->
    <iframe id="main-frame" src="about:blank" scrolling="yes" frameborder="0" style="width: 100%;height:100%;border: 0;"></iframe>
  </div>
  <!-- main end -->

  <!-- footer start -->
  <div class="layui-footer">
    <!-- 底部固定区域 -->
    <div class="layui-word-aux">&copy; Powered by <a href="https://yesu.co/" title="yesu.co" target="_blank" style="color: inherit;">yesu.co</a> {$version}</div>
  </div>
  <!-- footer end -->
</div>

<!-- javascript -->
<script>
  // JS 
  layui.use(['element', 'layer', 'util', 'jquery'], function () {
    var element = layui.element,
      layer = layui.layer,
      util = layui.util,
      $ = layui.jquery;

    // 头部事件
    var full = 1;
    var shrink = true;
    var hash = window.location.hash;
    $('#main-frame').attr('src', '{$site_url}/admin' + (hash.match(/^#\/[^#]+/) ? hash.replace('#', '') : '/index/welcome.html'));
    util.event('lay-header-event', {
      // 后台首页
      backend: function() {
        window.location.hash = '/';
        $('#main-frame').attr('src', '{$site_url}/admin/index/welcome.html');
      },
      // 左侧菜单事件
      menuLeft: function () {
        $('body').addClass('site-mobile');
        $('.layui-logo').removeClass('layui-hide-xs');
      },
      menuLeftShrink: function (obj) {
        if (shrink) {
          shrink = false;
          $('.layui-shrink').removeClass('layui-icon-shrink-right').addClass('layui-icon-spread-left');
          $('.layui-side').addClass('layui-side-shrink');
          $('.layui-logo').addClass('layui-logo-shrink');
          $('.layui-body').addClass('layui-body-shrink');
          $('.layui-layout-left').addClass('layui-layout-left-shrink');
          $('.layui-footer').addClass('layui-footer-shrink');
        } else {
          shrink = true;
          $('.layui-shrink').removeClass('layui-icon-spread-left').addClass('layui-icon-shrink-right');
          $('.layui-side').removeClass('layui-side-shrink');
          $('.layui-logo').removeClass('layui-logo-shrink');
          $('.layui-body').removeClass('layui-body-shrink');
          $('.layui-layout-left').removeClass('layui-layout-left-shrink');
          $('.layui-footer').removeClass('layui-footer-shrink');
        }
      },
      // 遮罩层收缩菜单
      menuShrink: function () {
        $('body').removeClass('site-mobile');
        $('.layui-logo').addClass('layui-hide-xs');
      },
      // 右侧菜单事件
      menuRight: function () {
        layer.open({
          type: 1,
          content: '<div class="layui-layer-content"><div class="layui-card-header">版本</div><div class="layui-card-body layui-text"><blockquote class="layui-elem-quote" style="border: none;">当前版本：{$version}</blockquote></div><div class="layui-card-header">关于</div><div class="layui-card-body layui-text"><blockquote class="layui-elem-quote" style="border: none;"> 原生手写 MVC 兼容 PHP5.4+ 它简单、易用、轻量，并且易于扩展！<br /><br />作者：葡萄枝子<br /><br />微信QQ 869026782 </blockquote></div><div class="layui-card-header">重置</div><div class="layui-card-body layui-text"><blockquote class="layui-elem-quote" style="border: none;">重置系统，将删除用户所有数据和附件，恢复到出厂设置。<br /><br /><button type="button" style="padding: 3px 8px;" lay-header-event="recovery">重置系统</button></blockquote></div></div>',
          area: ['260px', '100%'],
          offset: 'rt', //右上角
          anim: 5,
          shadeClose: true,
        });
      },
      // 刷新
      refresh: function () {
        window.location.reload();
      },
      // 全屏
      fullscreen: function () {
        if (full == 1) {
          var elem = document.documentElement;
          var reqFullScreen = elem.requestFullScreen || elem.webkitRequestFullScreen || elem.mozRequestFullScreen || elem.msRequestFullscreen;
          if (typeof reqFullScreen !== 'undefined' && reqFullScreen) {
            reqFullScreen.call(elem);
          };
          full = 2;
        } else {
          if (document.exitFullscreen) {
            document.exitFullscreen();
          } else if (document.mozCancelFullScreen) {
            document.mozCancelFullScreen();
          } else if (document.webkitCancelFullScreen) {
            document.webkitCancelFullScreen();
          } else if (document.msExitFullscreen) {
            document.msExitFullscreen();
          }
          full = 1;
        }
      },
      // 修改资料
      profile: function (othis) {
        layer.open({
          type: 2,
          maxmin: true,
          title: '修改资料',
          shadeClose: true,
          shade: 0.3,
          area: ['480px', '470px'],
          content: '{$site_url}/admin/profile.html',
        });
      },
      // 清除缓存
      clear: function (othis) {
        layer.confirm('确定清除缓存吗？', {
          btn: ['确定', '取消'], icon: 3
        }, function () {
          $.get('{$site_url}/admin/clear.html', {}, function (res) {
            if (res.code) return layer.alert(res.msg, { icon: 0 });
            layer.alert(res.msg, { icon: 1 }, function () {
              window.location.reload();
            });
          }, 'json');
        });
      },
      // 登出
      logout: function (othis) {
        layer.confirm('确定要登出站点吗？', {
          btn: ['确定', '取消']
        }, function () {
          $.post('{$site_url}/admin/logout.html', { redirect_to: '{$site_url}/' }, function (res) {
            if (res.code) return layer.alert(res.msg, { icon: 0 });
            layer.alert(res.msg, { icon: 1 });
            setTimeout(function () {
              window.location.href = res.url;
            }, 1000);
          }, 'json');
        });
      },
	  // 触发菜单
      fireMenu: function(othis) {
        var module = othis.data('module').toLowerCase();
        var controller = othis.data('controller').toLowerCase();
        var action = othis.data('action').toLowerCase();
        window.location.hash = '/' + controller + '/' + action + '.html';
        $('body').removeClass('site-mobile');
        $('.layui-logo').addClass('layui-hide-xs');
        $('#main-frame').attr('src', '{$site_url}/' + module + '/' + controller + '/' + action + '.html');
      },
	  // 重置系统
      recovery: function(othis) {
        layer.confirm('此操作恢复到出厂设置？', {
          title: '重置系统',
          btn: ['确定', '取消'],
          icon: 3
        }, function (index) {
          layer.close(index);
          layer.load(2);
          $.post('{$site_url}/admin/setting/recovery.html', {}, function (res) {
            layer.closeAll('loading');
            if (res.code) return layer.alert(res.msg, { icon: 0 });
            localStorage.removeItem('postViews');
            localStorage.removeItem('postFavorites');
            localStorage.removeItem('postLikes');
            layer.alert(res.msg, { icon: 1 });
          }, 'json');
        });
      }
    });

    // Cookie操作
    function setCookie(name, value, options) {
      options = options || {};
      if (value === null) {
          value = '';
          options.expires = -1;
      }
      var expires = '';
      if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
          var date;
          if (typeof options.expires == 'number') {
              date = new Date();
              date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
          } else {
              date = options.expires;
          }
          // use expires attribute, max-age is not supported by IE
          expires = '; expires=' + date.toUTCString();
      }
      var path = options.path ? '; path=' + options.path : '';
      var domain = options.domain ? '; domain=' + options.domain : '';
      var secure = options.secure ? '; secure' : '';
      var c = [name, '=', encodeURIComponent(value)].join('');
      var cookie = [c, expires, path, domain, secure].join('');
      document.cookie = cookie;
    }
    function getCookie(name) {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = cookies[i].trim();
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
  });
</script>

{include file='admin/footer.html'}